package com.dao.imp;

import com.dao.JobSeekerDao;
import com.entity.Resume;
import com.utils.DButil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JobSeekerDaoimpl implements JobSeekerDao {
    @Override
    public int AddResume(Resume resume) {
        Connection conn = DButil.getConn();
        String sql="insert  into r_resume(userid,jobid,auditstate,description,src,readstate) values(?,?,?,?,?,0) ";
        try {
            PreparedStatement ps= conn.prepareStatement(sql);
            ps.setString(1,resume.getUserId());
            ps.setString(2, String.valueOf(resume.getJobId()));
            ps.setString(3,resume.getAuditState());
            ps.setString(4,resume.getDescription());
            ps.setString(5,resume.getSrc());
            int i = ps.executeUpdate();
            if (i==1){
                return  1;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int AddFavoriteJob(Resume resume) {
        Connection conn = DButil.getConn();
        String sql="insert  into r_favoritesjob(userid,jobid) values(?,?) ";
        try {
            PreparedStatement ps= conn.prepareStatement(sql);
            ps.setString(1,resume.getUserId());
            ps.setString(2, String.valueOf(resume.getJobId()));
            int i = ps.executeUpdate();
            if (i==1){
                return  1;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
